#Fichero: Makefile

##############################
###### CONFIGURACION #########
##############################

BIN = ./bin
LIB = ./dist/lib
OBJ = ./obj

DEFS = ./ICE_defs
SKELS = ./ICE_skel

MAIN = .
INIT = ./initialize
AUXILIARY = ./auxiliary
EVENTS = ./events
DEFAULTS = $(EVENTS)/defaults
MYSQL = /usr/local/mysql

INCLUDE = -I$(SKELS)/ -I$(INIT)/ -I$(META_UTIL)/ -I$(AUXILIARY) -I$(EVENTS)/ -I$(MYSQL)/include/ -I$(MAIN)/ -I$(DEFAULTS)
SRC_COMPILER = g++-4.0
LD = ld
AR = ar
IDL_COMPILER = slice2cpp
IDL_OPTS = -I$(DEFS)/ --output-dir $(SKELS)/

CXX_OPTS = -O2 -fno-common -fPIC -Wall -gdwarf-2 -bind_at_load -D_REENTRANT -D__OSVERSION__=1 -D__darwin__ -D__x86__ -fno-inline
CXX_OPTS_MYSQL = -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT $(OPTS)
CXX_LIB_PATHS = -L$(MYSQL)/lib/
CXX_OMNI_LIBS = -lIce -lIceUtil -lIceStorm
CXX_LIBS = $(CXX_LIB_PATHS) $(CXX_OMNI_LIBS) -lmysqlclient -lz -lm -lmygcc

LINKOPTS = rcs
#DYNLINKOPTS = -dynamiclib -install_name @executable_path/Frameworks/libCollaboration.dylib
DYNLINKOPTS = -dynamiclib
DYNLINKIMPORTS = /usr/lib/bundle1.o

OBJS_SKEL = $(OBJ)/collaboration.o

OBJS_EVENTS = $(OBJ)/event.o $(OBJ)/eventConsumer.o $(OBJ)/eventSupplier.o $(OBJ)/eventListener.o $(OBJ)/eventHandler.o $(OBJ)/listeningObject.o

OBJS_INIT = $(OBJ)/coordinationMiddleware.o
OBJS_DEFAULTS = $(OBJ)/pairEvent.o $(OBJ)/drawingEvent.o $(OBJ)/drawingListener.o

OBJS_AUXILIARY = $(OBJ)/Thread.o

OBJS_MAIN_TEST = $(OBJ)/test_client.o

OBJS = $(OBJS_SKEL) $(OBJS_EVENTS) $(OBJS_INIT) $(OBJS_DEFAULTS) $(OBJS_AUXILIARY)

.PHONY = all clean dist

##############################
##### DESTINOS VIRTUALES #####
##############################

all: $(LIB)/libCollaboration.dylib $(LIB)/libCollaborationStatic.a $(BIN)/test_client

dist: $(LIB)/libCollaboration.dylib $(LIB)/libCollaborationStatic.a
	cp  $(SKELS)/*.h $(AUXILIARY)/*.h $(EVENTS)/*.h $(INIT)/*.h $(DEFAULTS)/*.h dist/include

clean:
	rm -f $(OBJ)/*
	rm -f $(LIB)/*
	rm -f $(BIN)/test_client

#############################
######  BIBLIOTECAS  ########
#############################

$(LIB)/libCollaboration.dylib : $(OBJS)
	$(SRC_COMPILER) $(DYNLINKOPTS) -o $(LIB)/libCollaboration.dylib $(OBJS) $(CXX_OMNI_LIBS)

$(LIB)/libCollaborationStatic.a : $(OBJS)
	$(AR) $(LINKOPTS) $(LIB)/libCollaborationStatic.a $(OBJS)

#############################
###### EJECUTABLES ##########
#############################

$(BIN)/test_client : $(OBJS_MAIN_TEST) $(LIB)/libCollaborationStatic.a
	$(SRC_COMPILER) -o $(BIN)/test_client $(OBJS_MAIN_TEST) -L$(LIB)/ -lCollaborationStatic $(CXX_OPTS) $(CXX_OMNI_LIBS)

##############################
######   ICE_SKEL   ########
##############################

$(SKELS)/collaboration.h : $(DEFS)/collaboration.ice
	$(IDL_COMPILER) $(IDL_OPTS) $(DEFS)/collaboration.ice
	
$(OBJ)/collaboration.o : $(SKELS)/collaboration.h $(SKELS)/collaboration.cpp
	$(SRC_COMPILER) -c $(SKELS)/collaboration.cpp -o $(OBJ)/collaboration.o $(CXX_OPTS) $(INCLUDE)


#############################
#######   EVENTS     ########
#############################

$(OBJ)/event.o : $(EVENTS)/event.cpp $(EVENTS)/event.h
	$(SRC_COMPILER) -c $(EVENTS)/event.cpp -o $(OBJ)/event.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/eventConsumer.o : $(EVENTS)/eventConsumer.cpp $(EVENTS)/eventConsumer.h
	$(SRC_COMPILER) -c $(EVENTS)/eventConsumer.cpp -o $(OBJ)/eventConsumer.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/eventSupplier.o : $(EVENTS)/eventSupplier.cpp $(EVENTS)/eventSupplier.h
	$(SRC_COMPILER) -c $(EVENTS)/eventSupplier.cpp -o $(OBJ)/eventSupplier.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/eventListener.o : $(EVENTS)/eventListener.cpp $(EVENTS)/eventListener.h
	$(SRC_COMPILER) -c $(EVENTS)/eventListener.cpp -o $(OBJ)/eventListener.o $(CXX_OPTS) $(INCLUDE)
	
$(OBJ)/eventHandler.o : $(EVENTS)/eventHandler.cpp $(EVENTS)/eventHandler.h
	$(SRC_COMPILER) -c $(EVENTS)/eventHandler.cpp -o $(OBJ)/eventHandler.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/listeningObject.o : $(EVENTS)/listeningObject.cpp $(EVENTS)/listeningObject.h
	$(SRC_COMPILER) -c $(EVENTS)/listeningObject.cpp -o $(OBJ)/listeningObject.o $(CXX_OPTS) $(INCLUDE)

##############################
######    AUXILIARY    #######
##############################

$(OBJ)/Thread.o : $(AUXILIARY)/Thread.cpp $(AUXILIARY)/Thread.h
	$(SRC_COMPILER) -c $(AUXILIARY)/Thread.cpp -o $(OBJ)/Thread.o $(CXX_OPTS) $(INCLUDE)

##############################
######      INIT       #######
##############################

$(OBJ)/coordinationMiddleware.o : $(INIT)/coordinationMiddleware.cpp $(INIT)/coordinationMiddleware.h
	$(SRC_COMPILER) -c $(INIT)/coordinationMiddleware.cpp -o $(OBJ)/coordinationMiddleware.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)

##############################
###         DEFAULTS        ##
##############################
	
$(OBJ)/pairEvent.o : $(DEFAULTS)/pairEvent.cpp $(DEFAULTS)/pairEvent.h
	$(SRC_COMPILER) -c $(DEFAULTS)/pairEvent.cpp -o $(OBJ)/pairEvent.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/drawingEvent.o : $(DEFAULTS)/drawingEvent.cpp $(DEFAULTS)/drawingEvent.h
	$(SRC_COMPILER) -c $(DEFAULTS)/drawingEvent.cpp -o $(OBJ)/drawingEvent.o $(CXX_OPTS) $(INCLUDE)
	
$(OBJ)/drawingListener.o : $(DEFAULTS)/drawingListener.cpp $(DEFAULTS)/drawingListener.h
	$(SRC_COMPILER) -c $(DEFAULTS)/drawingListener.cpp -o $(OBJ)/drawingListener.o $(CXX_OPTS) $(INCLUDE)


##############################
#######     MAIN       #######
##############################

$(OBJ)/test_client.o : $(MAIN)/test_client.cpp
	$(SRC_COMPILER) -c $(MAIN)/test_client.cpp -o $(OBJ)/test_client.o $(CXX_OPTS) $(INCLUDE)

